/**
 * Created with Vim7.3 ubuntu12.04
 * @fileOverview : 
 * @author : Lyle
 * @since : 2015-03-16 14:26:22
 * @filename : public/js/common.js
 * @version : 
 * @description : 
 */

;(function(win){
   var common = win.common = {};

   common.Loading = function(dom,bool) {
         if (bool) {
             var html = "<div id='pageLoad'></div>";
             var chtml = "<div id='pageLoadDiv'></div>";
             if ($('#pageLoad').length<1) {
                 dom.append(html);
             }

             if ($('#pageLoadDiv').length < 1) {
                 chtml = $(chtml).on('touchstart touchmove touchend',function(e){
                     e.stopPropagation(); 
                     e.preventDefault(); 
                 });
                 dom.append(chtml);
             }

         } else {
            dom.find('#pageLoad').remove();
            dom.find('#pageLoadDiv').remove();
         }
   };

   common.openTopError = function(opt) {
         window.scroll(0,0);
         var tthis = this,
             html = '<div class="'+opt.type+'"> <span class="promptTip_left"></span> <span class="promptTip_content"> '+opt.text+'</span> <span class="promptTip_right"> X </span> </div>';
        
         html = $(html);

         $(html).find('.promptTip_right').on('tap',function(){
             html.remove();                 
         });

         opt.dom.html(html); 

         if (opt.time) {
             setTimeout(function(){
                 html.remove();
             },opt.time);
         }

   };

   common.closeTopError = function() {

   };

   common.ajax = function(obj) {
         $.ajax(obj);
   };

   common.checkCard = function(num) {
        var type, 
            visa = /^4[0-9]{12}(?:[0-9]{3})?$/,
            mastercard = /^5[1-5][0-9]{14}$/,
            amex = /^3[47][0-9]{13}$/;
 
        if (visa.test(num)) {
            type = 'visa';
        } else if (amex.test(num)) {
            type = 'amex';
        } else if(mastercard.test(num)) {
            type = 'mastercard';
        }
        return type;
   };



})(window);

